{% import 'languages/'+lang|default('en')+'.html' as lang %}
{% set services_name = {
	'roxy-wi-checker': { 'name': 'Checker', 'desc': lang.admin_page.desc.checker_desc },
	'roxy-wi-keep_alive': { 'name': 'Auto start', 'desc': lang.admin_page.desc.auto_start_desc },
	'roxy-wi-metrics': { 'name': 'Metrics', 'desc': lang.admin_page.desc.metrics_desc },
	'roxy-wi-portscanner': { 'name': 'Port scanner', 'desc': lang.admin_page.desc.p_s_desc },
	'roxy-wi-smon': { 'name': 'SMON', 'desc': lang.admin_page.desc.smon_desc },
	'roxy-wi-socket': { 'name': 'Socket', 'desc': lang.admin_page.desc.socket_desc },
	'roxy-wi-prometheus-exporter': { 'name': 'Prometheus exporter', 'desc': 'Prometheus exporter exports Roxy-WI metrics' },
	'prometheus': { 'name': 'Prometheus', 'desc': 'Prometheus server' },
	'grafana-server': { 'name': 'Grafana', 'desc': 'Grafana server' },
	'fail2ban': { 'name': 'Fail2ban', 'desc': 'Fail2ban scans log files (e.g. /var/log/apache/error_log) and bans IPs that show the malicious signs' },
    'rabbitmq-server': { 'name': 'RabbitMQ', 'desc': 'RabbitMQ server' },
    }
%}
{% for service in services %}
{% set is_service_started_class = '' %}
{% set is_service_stopped_class = '' %}
{% set onclick_start_action = "confirmAjaxServiceAction('start', '"+service.0+"')" %}
{% set onclick_stop_action = "confirmAjaxServiceAction('stop', '"+service.0+"')" %}
{% set is_service_started_title = lang.words.start|title()+" "+lang.words.and+" "+lang.words.enable+" "+services_name[service.0]['name']+" "+lang.words.service %}
{% set is_service_stopped_title = lang.words.stop|title()+" "+lang.words.and+" "+lang.words.disable+" "+services_name[service.0]['name']+" "+lang.words.service %}
<tr class="{{ loop.cycle('odd', 'even') }}" id="{{service.0}}">
    <td class="padding10 first-collumn">
        {% if service.1 == 'active' or service.1 == 'RUNNING' %}
            <span title="{{lang.words.service|title()}} {{services_name[service.0]['name']}} {{lang.words.started}}"><span class="serverUp server-status"></span></span>
            {% set is_service_started_class = 'disabled-button' %}
            {% set onclick_start_action = "" %}
            {% set is_service_started_title = lang.words.service|title()+" "+services_name[service.0]['name']+" "+lang.words.already+" "+lang.words.started %}
        {% else %}
            {% if (service.1 == 'inactive' or service.1 == 'failed' or service.1 == 'activating' or service.1 == 'STOPPED') and 'is not installed' not in service.2['current_version'] %}
                <span title="{{lang.words.service|title()}} {{services_name[service.0]['name']}} {{lang.words.stopped}}"><span class="serverDown server-status"></span></span>
                {% set is_service_stopped_class = 'disabled-button' %}
                {% set onclick_stop_action = "" %}
                {% set is_service_stopped_title = lang.words.service|title()+" "+services_name[service.0]['name']+" "+lang.words.already+" "+lang.words.stopped %}
            {% else %}
                <span title="{{lang.words.service|title()}} {{services_name[service.0]['name']}} {{lang.words.not}} {{lang.words.installed}}"><span class="serverNone server-status"></span></span>
            {% endif %}
        {% endif %}
        {{services_name[service.0]['name']}}
    </td>
    <td class="padding10 first-collumn">
        {% if 'is not installed' in service.2['current_version'] or not service.2['current_version'] or service.2['current_version'] == '0' %}
            {% if service.0 in ('prometheus', 'grafana-server') %}
                <a href="/app/install#monitoring" class="ui-button ui-widget ui-corner-all" title="{{lang.words.install|title()}} {{service_name}}">{{lang.words.install|title()}}</a>
            {% elif service.0 in ('rabbitmq-server', 'fail2ban') %}
                <a class="ui-button ui-widget ui-corner-all" href="https://roxy-wi.org/tools/{{service.0.split('-')[0]}}" title="{{lang.words.install|title()}} {{services_name[service.0]['name']}}" target="_blank">{{lang.words.install|title()}}</a>
            {% else %}
                <a class="ui-button ui-widget ui-corner-all" onclick="updateService('{{service.0}}', 'install')" title="{{lang.words.install|title()}} {{service_name}}">{{lang.words.install|title()}}</a>
            {% endif %}
        {% else %}
        <a id="start-{{ service.0 }}" class="start" title="{{is_service_started_title}}">
            <span class="service-start {{is_service_started_class}}" onclick="{{onclick_start_action}}"></span>
        </a>
        <a id="restart-{{ service.2 }}" class="restart" title="{{lang.words.restart|title()}} {{services_name[service.0]['name']}} {{lang.words.service}}">
            <span class="service-reload service-restart" onclick="confirmAjaxServiceAction('restart', '{{service.0}}')"></span>
        </a>
        <a id="stop-{{ service.0 }}" class="stop" title="{{is_service_stopped_title}}">
            <span class="service-stop {{is_service_stopped_class}}" onclick="{{onclick_stop_action}}"></span>
        </a>
        {% endif %}
    </td>
    <td>
        {% if 'is not installed' not in service.2['current_version'] %}
        {{service.2['current_version']}}
        {% endif %}
    </td>
    <td colspan="2">
        {{ services_name[service.0]['desc'] | safe }}
    </td>
</tr>
{% endfor %}
